#!/usr/bin/env python
# encoding: utf-8
"""
@author: youfeng
@email: youfeng243@163.com
@license: Apache Licence 
@file: kafka_producer.py
@time: 2016/12/19 16:32
"""
import time

from pykafka import KafkaClient

# client = KafkaClient(hosts="182.61.44.214:9092,10.66.246.141:9092,182.61.26.153:9092")  # 可接受多个Client这是重点
client = KafkaClient(hosts='172.18.180.223:9092,172.18.180.222:9092,172.18.180.225:9092')  # 可接受多个Client这是重点
print client.topics  # 查看所有topic
topic = client.topics['test']  # 选择一个topic
producer = topic.get_producer()
while True:
    producer.produce('test message')  # 加了个str官方的例子py2.7跑不过
    time.sleep(5)
    print '发送消息...'
